package main

import (
	"context"
	"gitee.com/kaylee595/yesCaptcha"
	"gitee.com/kaylee595/yesCaptcha/taskType/recaptchaV2"
	"log/slog"
	"time"
)

func main() {
	const clientKey = "" // 请填写你的clientKey
	client := yesCaptcha.NewClient(clientKey, yesCaptcha.WithSoftId(61751))
	start := time.Now()
	respCreateTask, err := client.CreateTask(context.Background(), recaptchaV2.Task{
		Type:       recaptchaV2.TypeNoCaptchaTaskProxyless,
		WebsiteURL: "https://www.52pojie.cn/member.php?mod=logging&action=login",
		WebsiteKey: "6LftSMEUAAAAANe9O4IJt4lDNV2naDxJwOu88w5o",
	})
	if err != nil {
		panic(err)
	}
	ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
	defer cancel()
	taskResult, err := yesCaptcha.AwaitGetTaskResult(ctx, func() (*yesCaptcha.RespGetTaskResult[recaptchaV2.Solution], error) {
		r, err := client.GetTaskResult(context.Background(), respCreateTask.TaskId)
		if err != nil {
			return nil, err
		}
		return yesCaptcha.TaskResultTo[recaptchaV2.Solution](r)
	})
	if err != nil {
		panic(err)
	}
	slog.Info("识别成功", "gRecaptchaResponse", taskResult.Solution.GRecaptchaResponse, "耗时", time.Since(start))
}
